package com.intel.two.controller.information;

import com.intel.two.common.LayuiPageVo;
import com.intel.two.common.R;
import com.intel.two.pojo.information.Find;
import com.intel.two.service.information.FindService;
import com.intel.two.utils.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.util.Map;

@RestController
@RequestMapping("/find")
public class FindController {
    @Autowired
    private FindService findService;

    /*查全部+分页*/
    @RequestMapping("/findList")
    public LayuiPageVo<Find> findPageData(@RequestParam Map<String, Object> params) {
        System.out.println(params);
        return findService.findPageData(params);
    }

    /*增加*/
    @PostMapping("/addFind")
    public R addFind(Find find) {
        System.out.println(find);
        int result = findService.addFind(find);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    @PostMapping("/uploadPic")
    public R uploadPic(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        String fileUrl = OssUtil.updateLoad(file.getInputStream(), originalFilename);
        return R.ok().data("url",fileUrl);
    }

    @GetMapping("/deleteFind")
    public R deleteFind(Integer find_id) {
        int result = findService.deleteFind(find_id);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @GetMapping("/deleteFindAll")
    public R deleteFindAll(@RequestParam Map<String, Object> map) {
        int result = findService.deleteFindAll(map);
        if (result > 0) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    @PostMapping("updateFind")
    public R updateFind(Find find) {
        System.out.println(find);
        int result = findService.updateFind(find);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }


}